#define _CRT_SECURE_NO_WARNINGS  1
#include<stdio.h>
int majorityElement(int* nums, int numsSize)
{
    for (int i = 0; i < numsSize - 1; i++)
    {
        for (int j = 0; j < numsSize - 1 - i; j++)
        {
            if (nums[j] > nums[j + 1])
            {
                int tmp;
                tmp = nums[j];
                nums[j] = nums[j + 1];
                nums[j + 1] = tmp;
            }
        }
    }
    int left = 0, right = 1;
    int count = 1;
    while (right != numsSize)
    {
        if (nums[right] == nums[left])
        {
            right++;
            count++;
            if (count > numsSize / 2)
            {
                return nums[left];
            }
        }
        else
        {
            count = 1;
            left = right;
            right++;
        }
    }
}
int main()
{
    int nums[7] = { 2,2,1,1,1,2,2 };
    printf("%d", majorityElement(nums, 7));
    return 0;
}